package com.example.lib_common.mvi.custom

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import com.example.lib_common.R

class StepView(context: Context, attrs: AttributeSet) : View(context, attrs) {
    private lateinit var mPaint: Paint
    private lateinit var paint: Paint
    private lateinit var textPaint: Paint
    private lateinit var selBitMap: Bitmap
    var startX =0F
    var startY =0F
    lateinit var  txt :String

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        startX= (measuredWidth/3).toFloat()
        startY= (measuredHeight/2).toFloat()
    }
    init {
        val typedArray  = context.obtainStyledAttributes(attrs, R.styleable.StepView)
         txt = typedArray.getString(R.styleable.StepView_txt).toString()
        mPaint = Paint()
        mPaint.setAntiAlias(true) //设置是否抗锯齿;
        mPaint.setStyle(Paint.Style.FILL); //设置填充样式
        mPaint.setColor(Color.parseColor("#0277FF"));//设置画笔颜色
        mPaint.setStrokeWidth(8F);//设置画笔宽度

        paint = Paint()
        paint.setAntiAlias(true) //设置是否抗锯齿;
        paint.setStyle(Paint.Style.FILL); //设置填充样式
        paint.color=Color.RED//设置画笔颜色
        paint.setStrokeWidth(8F);//设置画笔宽度

        textPaint = Paint()
        textPaint.setAntiAlias(true) //设置是否抗锯齿;
        textPaint.setStyle(Paint.Style.FILL); //设置填充样式
        textPaint.color=Color.BLACK//设置画笔颜色
        textPaint.setStrokeWidth(2F);//设置画笔宽度
        textPaint.textSize=25F
        selBitMap=BitmapFactory.decodeResource(resources, R.drawable.start)
    }
    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        val mMatrix = Matrix()
        val mMatrix1 = Matrix()
        val mMatrix3 = Matrix()
        mMatrix.preTranslate( startX/2-selBitMap.width/2,startY-selBitMap.height/2)
        mMatrix1.preTranslate((startX*1.5-selBitMap.width/2).toFloat(),startY-selBitMap.width/2)
        mMatrix3.preTranslate((startX*2.5-selBitMap.width/2).toFloat(),startY-selBitMap.width/2)

        canvas!!.drawCircle(startX/2,startY,40F,mPaint)
        canvas!!.drawBitmap(selBitMap,mMatrix,mPaint)
        canvas!!.drawLine(startX/2+40,startY, (startX*1.5).toFloat(),startY,mPaint)
        canvas.drawText("提交",startX/2-25,startY+75,textPaint)
        if (txt=="车位"){
            canvas.drawText("车管员同意", (startX*1.5-25*2).toFloat(),startY+75,textPaint)
            canvas.drawText("部门经理", (startX*2.5-25*2).toFloat(),startY+75,textPaint)
        }else if (txt=="来访"){
            canvas.drawText("步骤2", (startX*1.5-25*2).toFloat(),startY+75,textPaint)
            canvas.drawText("步骤3", (startX*2.5-25*2).toFloat(),startY+75,textPaint)
        }else if (txt=="维修"){
            canvas.drawText("维修员确认", (startX*1.5-25*2).toFloat(),startY+75,textPaint)
            canvas.drawText("客户确认", (startX*2.5-25*2).toFloat(),startY+75,textPaint)
        }
        canvas!!.drawCircle((startX*1.5).toFloat(),startY,40F,mPaint)
        canvas!!.drawBitmap(selBitMap,mMatrix1,mPaint)
        canvas!!.drawLine((startX*1.5+40).toFloat(),startY, (startX*2.5).toFloat(),startY,paint)

        canvas!!.drawCircle((startX*2.5).toFloat(),startY,40F,paint)
        canvas!!.drawBitmap(selBitMap,mMatrix3,mPaint)
    }
}